package com.meida.module.bus.provider.api.service;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.log.StaticLog;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.util.TypeUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.meida.common.mybatis.entity.EntityMap;
import com.meida.common.security.OpenHelper;
import com.meida.common.utils.RedisUtils;
import com.meida.module.bus.client.entity.*;
import com.meida.module.bus.client.entity.srmapi.oa.ApprovalReq;
import com.meida.module.bus.client.entity.srmapi.oa.BpmMainDo;
import com.meida.module.bus.client.entity.srmapi.oa.BusOaApprovalSync;
import com.meida.module.bus.client.entity.srmapi.oa.BusOaApprovalSyncDetail;
import com.meida.module.bus.client.entity.srmapi.srmtopms.SrmPms05Req;
import com.meida.module.bus.provider.api.util.ApiConstants;
import com.meida.module.bus.provider.api.util.PmsApiUtil;
import com.meida.module.bus.provider.api.util.PmsOaUtil;
import com.meida.module.bus.provider.api.util.PmsToolUtil;
import com.meida.module.bus.provider.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

@Service
public class SyncOASubService {
    @Autowired
    private BusMasterAlldataViewService alldataViewService;
    @Autowired
    private BusProjectService projectService;
    @Autowired
    private PmsOaUtil pmsOaUtil;
    @Autowired
    private PmsApiUtil pmsApiUtil;
    @Autowired
    private BusPurchaseService purchaseService;
    @Autowired
    private BusPurchaseDetailsService purchaseDetailsService;
    @Autowired
    private SyncSrmSubService syncSrmSubService;
    @Autowired
    private BusMaterialService busMaterialService;
    @Autowired
    private BusMaterialPlan100Service plan100Service;
    @Autowired
    private BusMaterialPlan200Service plan200Service;
    @Autowired
    private BusMaterialPackage100Service package100Service;
    @Autowired
    private BusMaterialPackage200Service package200Service;
    @Autowired
    private BusReportService busReportService;
    @Autowired
    private SyncSrmService syncSrmService;
    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private BusMajorService busMajorService;

    /**
     * 获取通用审批流请求信息
     *
     * @param reqData
     * @param approvalUrl
     * @param userNum
     * @param appKind
     * @param projectId
     * @return
     */
    public ApprovalReq getApproval(Object reqData, String approvalUrl, String userNum, String appKind, String projectId) {
        ApprovalReq approvalReq = new ApprovalReq();
        // 员工工号
        approvalReq.setUserNum(userNum);
        // 审批单据名称
        approvalReq.setApprovalDocnm(appKind);
        // 审批详情连接
        approvalReq.setApprovalUrl(approvalUrl);
        return approvalReq;
    }

    /**
     * 组装OA审批流数据
     *
     * @param reqData     请求数据
     * @param approvalUrl 请求URL
     * @param userNum     审批发起人
     * @param appKind     各审批流调用参数列表
     *                    商务角色：工程量清单转100版本的审批   ApiConstants.BUSINESS_APPROVAL_100
     *                    商务角色：材料计划转200版本审批      ApiConstants.BUSINESS_APPROVAL_WZ_100
     *                    商务角色：分包计划转200版本审批      ApiConstants.BUSINESS_APPROVAL_FB_100
     *                    商务角色：分包合同下达审批           ApiConstants.BUSINESS_APPROVAL_FB_CONTACTS
     *                    商务角色：对外验工月报审批           ApiConstants.BUSINESS_APPROVAL_REPORT_OUT
     *                    <p>
     *                    【材料计划】
     *                    工程师角色：100版本_修正变更审批     ApiConstants.ENGINEER_APPROVAL_WZ_100_UPD
     *                    工程师角色：100版本_追加变更审批     ApiConstants.ENGINEER_APPROVAL_WZ_100_ADD
     *                    工程师角色：200版本_修正变更审批     ApiConstants.ENGINEER_APPROVAL_WZ_200_UPD
     *                    工程师角色：200版本_追加变更审批     ApiConstants.ENGINEER_APPROVAL_WZ_200_ADD
     *                    【分包计划】
     *                    工程师角色：100版本_修正变更审批     ApiConstants.ENGINEER_APPROVAL_FB_100_UPD
     *                    工程师角色：100版本_追加变更审批     ApiConstants.ENGINEER_APPROVAL_FB_100_ADD
     *                    工程师角色：200版本_修正变更审批     ApiConstants.ENGINEER_APPROVAL_FB_200_UPD
     *                    工程师角色：200版本_追加变更审批     ApiConstants.ENGINEER_APPROVAL_FB_200_ADD
     *                    <p>
     *                    工程师角色：材料计划申请_审批        ApiConstants.ENGINEER_APPROVAL_WZ_REQ
     *                    工程师角色：对内验工月报_审批        ApiConstants.ENGINEER_APPROVAL_FB_REQ
     * @param projectId   项目ID
     * @return 审批数据结构
     */
    public BpmMainDo getApprovalObj(Object reqData, String approvalUrl,
                                    String userNum, String appKind, String projectId,
                                    List<BusOaApprovalSyncDetail> syncOaDetailList, BusOaApprovalSync busOaApprovalSync) throws Exception {
        String majorCode = "";
        List<String> majorCodes = busMajorService.getUserMajors(OpenHelper.getUserId());
        if (majorCodes.size() > 0) {
            if (!majorCodes.contains("P99")) {
                majorCode = majorCodes.get(0);
            }
        }

        BpmMainDo bpmMainDo = new BpmMainDo();
        // 审批人
        bpmMainDo.setUserNum(userNum);
        // 审批发起时间
        bpmMainDo.setApplydate(DateUtil.now());
        // 审批项目经理
        bpmMainDo.setXmjlgh(pmsOaUtil.getXmjlNm(Long.valueOf(projectId)));
        // 审批流名称
        bpmMainDo.setWorkflowname(pmsOaUtil.getWorkflowname(appKind, 0));

        // 商务角色：工程量清单的100版本的审批
        if (ApiConstants.BUSINESS_APPROVAL_100.equals(appKind)) {
            // 审批数据组装
            getBpmMainDoForBus1(bpmMainDo, Long.valueOf(projectId), appKind);
        } else if (ApiConstants.BUSINESS_APPROVAL_WZ_100.equals(appKind)) {
            // 材料计划转200版本审批
            // 审批数据组装
            getBpmMainDoForBus2(bpmMainDo, Long.valueOf(projectId), appKind);
        } else if (ApiConstants.BUSINESS_APPROVAL_FB_100.equals(appKind)) {
            // 分包计划转的200版本审批s
            // 审批数据组装
            getBpmMainDoForBus3(bpmMainDo, reqData, Long.valueOf(projectId), appKind);
        } else if (ApiConstants.BUSINESS_APPROVAL_FB_CONTACTS.equals(appKind)) {
            // 分包合同下达审批
            // 审批数据组装
            getBpmMainDoForBus4(bpmMainDo, reqData, Long.valueOf(projectId), appKind);
        } else if (ApiConstants.BUSINESS_APPROVAL_REPORT_OUT.equals(appKind)) {
            // 对外验工月报审批
            // 审批数据组装
        } else if (
            ApiConstants.ENGINEER_APPROVAL_WZ_100_UPD.equals(appKind)
                || ApiConstants.ENGINEER_APPROVAL_WZ_100_ADD.equals(appKind)
                || ApiConstants.ENGINEER_APPROVAL_WZ_200_UPD.equals(appKind)
                || ApiConstants.ENGINEER_APPROVAL_WZ_200_ADD.equals(appKind)
                || ApiConstants.ENGINEER_APPROVAL_FB_100_UPD.equals(appKind)
                || ApiConstants.ENGINEER_APPROVAL_FB_100_ADD.equals(appKind)
                || ApiConstants.ENGINEER_APPROVAL_FB_200_UPD.equals(appKind)
                || ApiConstants.ENGINEER_APPROVAL_FB_200_ADD.equals(appKind)
        ) {
            Collection<Object> reqS = pmsOaUtil.getPlanPackData(appKind, Long.valueOf(projectId));
            // 组装请求数据
            StaticLog.info("审批信息reqS.size()-----------------------------------：" + reqS.size());
            StaticLog.info("审批信息bpmMainDo-----------------------------------：" + JSONObject.toJSONString(bpmMainDo));
            pmsOaUtil.setBpmReqObj(bpmMainDo, reqS.stream().findFirst().get(), reqS, appKind);
            // 审批预览URL
            approvalUrl = approvalUrl + "?projectId=" + projectId;
            if (StrUtil.isNotEmpty(majorCode)) {
                approvalUrl = approvalUrl + "&majorCode=" + majorCode;
            }
            bpmMainDo.setApprovalUrl(approvalUrl);
            busOaApprovalSync.setMajorCode(PmsToolUtil.getStrValue(reqS.stream().findFirst().get(), ApiConstants.INVOKE_GET_MAJORCODE));
            busOaApprovalSync.setPackageNo(PmsToolUtil.getStrValue(reqS.stream().findFirst().get(), ApiConstants.INVOKE_GET_PACKAGENO));
            // 面向计划数据-记录同步子项目
            pmsOaUtil.setSyncOaDetailListForPlanData(reqS, syncOaDetailList, appKind);

        } else if (ApiConstants.ENGINEER_APPROVAL_WZ_REQ.equals(appKind)) {
            Map<String, Object> reqDataMap = (Map) reqData;
            BusPurchase busPurchase = (BusPurchase) reqDataMap.get("purchase");
            List<BusMaterialPlan100> pnlist = (List<BusMaterialPlan100>) reqDataMap.get("plan100detail");
            // 材料计划申请_审批
            // 审批数据组装
            // 组装请求数据
            pmsOaUtil.setBpmReqObj(bpmMainDo,
                busPurchase,
                busPurchase.getDetails().stream().collect(Collectors.toList()),
                appKind);
            // 审批预览URL
            approvalUrl = approvalUrl + "?projectId=" + projectId;
            if (StrUtil.isNotEmpty(majorCode)) {
                approvalUrl = approvalUrl + "&majorCode=" + majorCode;
            }
            bpmMainDo.setApprovalUrl(approvalUrl);
            // 面向材料申请数据-记录同步子项目
            pmsOaUtil.setSyncOaDetailListForApplayData(busPurchase.getDetails(), syncOaDetailList, appKind);

        } else if (ApiConstants.ENGINEER_APPROVAL_FB_REQ.equals(appKind)) {
            Map<String, Object> approvalMap = (Map<String, Object>) reqData;
            List<BusReport> busReports = (List<BusReport>) approvalMap.get(ApiConstants.REDIS_KEY_BUSREPORT_APPROVALS);
//            Integer ver = Integer.valueOf(String.valueOf(approvalMap.get(ApiConstants.REDIS_KEY_BUSREPORT_VER)));
//            List<BusReport> busReports = (List<BusReport>) reqData;
            // 对内验工月报_审批
            // 审批数据组装
            // 组装请求数据
            pmsOaUtil.setBpmReqObj(bpmMainDo,
                busReports.get(0),
                busReports.stream().collect(Collectors.toList()),
                appKind);
            // 审批预览URL
            approvalUrl = approvalUrl + "?projectId=" + projectId;
            if (StrUtil.isNotEmpty(majorCode)) {
                approvalUrl = approvalUrl + "&majorCode=" + majorCode;
            }
            bpmMainDo.setApprovalUrl(approvalUrl);
            // 面向材对内验工月报-记录同步子项目
            pmsOaUtil.setSyncOaDetailListForPackageApplayData(busReports, syncOaDetailList, appKind);
        }
        BusProject busProject = pmsApiUtil.getProjectInfo(Long.valueOf(projectId));
        bpmMainDo.setItem3(busProject.getProjectCode());
        bpmMainDo.setItem4(busProject.getProjectName());
        bpmMainDo.setItem7(busProject.getGoodsPurGroupName());
        return bpmMainDo;
    }

    /**
     * 组装OA审批流数据
     *
     * @param reqData     请求数据
     * @param approvalUrl 请求URL
     * @param userNum     审批发起人
     * @param appKind     各审批流调用参数列表
     *                    商务角色：分包合同下达审批           ApiConstants.BUSINESS_APPROVAL_FB_CONTACTS
     * @param projectId   项目ID
     * @return 审批数据结构
     */
    public List<BpmMainDo> getApprovalObjForBus4(Object reqData, String approvalUrl, String userNum, String appKind, String projectId) throws Exception {
        BpmMainDo bpmMainDo = new BpmMainDo();
        // 审批人
        bpmMainDo.setUserNum(userNum);
        // 审批发起时间
        bpmMainDo.setApplydate(DateUtil.now());
        // 审批预览URL
        bpmMainDo.setApprovalUrl(approvalUrl);
        // 审批项目经理
        bpmMainDo.setXmjlgh(pmsOaUtil.getXmjlNm(Long.valueOf(projectId)));
        // 审批流名称
        bpmMainDo.setWorkflowname(pmsOaUtil.getWorkflowname(appKind, 0));

        Map<String, String> inMap = (Map) reqData;
        String majorCode = inMap.get(ApiConstants.MAP_MAJORCODE);
        String packageNo = inMap.get(ApiConstants.MAP_PACKAGENO);
        int ver = Integer.valueOf(inMap.get(ApiConstants.MAP_PACKAGENO));
        List<SrmPms05Req> srmPms05Reqs = syncSrmSubService.getSrmPms05Req(Long.valueOf(projectId), majorCode, packageNo, ver, OpenHelper.getUserName());
        List<BpmMainDo> bpmMainDoList = Lists.newArrayList();
        srmPms05Reqs.stream().forEach(srmPms05Req -> {
            Collection<Object> srm05S = Collections.emptyList();
            srm05S.addAll(srmPms05Req.getDetails());
            // 组装请求数据
            pmsOaUtil.setBpmReqObj(bpmMainDo,
                srmPms05Req,
                srm05S,
                appKind);
            bpmMainDoList.add(bpmMainDo);
        });

        return bpmMainDoList;
    }

    /**
     * 商务角色：工程量清单转100版本的审批   ApiConstants.BUSINESS_APPROVAL_100
     *
     * @param bpmMainDo 数据
     * @param projectId 项目ID
     */
    public void getBpmMainDoForBus1(BpmMainDo bpmMainDo, Long projectId, String appKind) {
        Map<String, Object> searchMap = Maps.newHashMap();
        searchMap.put(ApiConstants.MAP_PROJECTCODE, pmsApiUtil.getProjectInfo(projectId).getProjectCode());
        Collection<Object> busMasterAlldataViews = alldataViewService.listByMap(searchMap).stream().collect(Collectors.toList());
        if (0 < busMasterAlldataViews.size()) {
            // 组装请求数据
            pmsOaUtil.setBpmReqObj(bpmMainDo,
                busMasterAlldataViews.stream().findFirst().get(),
                busMasterAlldataViews,
                appKind);
        }
    }

    /**
     * 商务角色：材料计划转200版本审批   ApiConstants.BUSINESS_APPROVAL_100
     *
     * @param bpmMainDo 数据
     * @param projectId 项目ID
     */
    public void getBpmMainDoForBus2(BpmMainDo bpmMainDo, Long projectId, String appKind) {
        Map<String, Object> searchMap = Maps.newHashMap();
        searchMap.put(ApiConstants.MAP_PROJECTCODE, pmsApiUtil.getProjectInfo(projectId).getProjectCode());
        searchMap.put(ApiConstants.MAP_TYPE, "100材料");
        Collection<Object> busMasterAlldataViews = alldataViewService.listByMap(searchMap).stream().collect(Collectors.toList());
        if (0 < busMasterAlldataViews.size()) {
            // 组装请求数据
            pmsOaUtil.setBpmReqObj(bpmMainDo,
                busMasterAlldataViews.stream().findFirst().get(),
                busMasterAlldataViews,
                appKind);
        }
    }

    /**
     * 商务角色：分包计划转200版本审批      ApiConstants.BUSINESS_APPROVAL_FB_100
     *
     * @param bpmMainDo 数据
     * @param projectId 项目ID
     */
    public void getBpmMainDoForBus3(BpmMainDo bpmMainDo, Object reqData, Long projectId, String appKind) {
        Map<String, Object> searchMap = Maps.newHashMap();
        searchMap.put(ApiConstants.MAP_PROJECTCODE, pmsApiUtil.getProjectInfo(projectId).getProjectCode());
        searchMap.put(ApiConstants.MAP_TYPE, "100分包");
        Collection<Object> busMasterAlldataViews = alldataViewService.listByMap(searchMap).stream().collect(Collectors.toList());
        if (0 < busMasterAlldataViews.size()) {
            // 组装请求数据
            pmsOaUtil.setBpmReqObj(bpmMainDo,
                busMasterAlldataViews.stream().findFirst().get(),
                busMasterAlldataViews,
                appKind);
        }
    }

    /**
     * 商务角色：分包合同下达审批      ApiConstants.BUSINESS_APPROVAL_FB_CONTACTS
     *
     * @param bpmMainDo 数据
     * @param projectId 项目ID
     */
    public void getBpmMainDoForBus4(BpmMainDo bpmMainDo, Object reqData, Long projectId, String appKind) {
        Map<String, Object> reqMap = (Map) reqData;
        Collection<Object> details = null;
//        if (null != reqMap.get(ApiConstants.OA_BUS4_BODY_INFO)) {
//            details = (Collection<Object>) reqMap.get(ApiConstants.OA_BUS4_BODY_INFO);
//        }
//        if (null != reqMap.get(ApiConstants.OA_BUS4_HEADER_INFO)) {
        // 组装请求数据
        pmsOaUtil.setBpmReqObj(bpmMainDo,
            reqMap.get(ApiConstants.OA_BUS4_HEADER_INFO),
            details,
            appKind);
//        }
    }

    /**
     * 商务角色：对外验工月报审批           ApiConstants.BUSINESS_APPROVAL_REPORT_OUT
     *
     * @param bpmMainDo 数据
     * @param projectId 项目ID
     */
    public void getBpmMainDoForBus5(BpmMainDo bpmMainDo, Object reqData, Long projectId, String appKind) {
        // TODO:组装中
        Map<String, Object> searchMap = Maps.newHashMap();
        searchMap.put(ApiConstants.MAP_PROJECTCODE, pmsApiUtil.getProjectInfo(projectId).getProjectCode());
        Collection<Object> busMasterAlldataViews = alldataViewService.listByMap(searchMap).stream().collect(Collectors.toList());
        if (0 < busMasterAlldataViews.size()) {
            // 组装请求数据
            pmsOaUtil.setBpmReqObj(bpmMainDo,
                busMasterAlldataViews.stream().findFirst().get(),
                busMasterAlldataViews,
                appKind);
        }
    }

    /**
     * 工程师角色：100版本_修正变更审批     ApiConstants.ENGINEER_APPROVAL_WZ_100_UPD
     *
     * @param bpmMainDo 数据
     * @param projectId 项目ID
     */
    public void getBpmMainDoForEng(BpmMainDo bpmMainDo, Object reqData, Long projectId, String appKind) {

    }

    public void todoMake(Long projectId, String appKind, Object reqData, String userNum) throws Exception {

        StaticLog.info("------todoMake-----start");
        if (ApiConstants.BUSINESS_APPROVAL_100.equals(appKind)) {
            StaticLog.info("工程量清单的100版本的审批--goArchive100---start");
            // 工程量清单的100版本的审批
            busMaterialService.goArchive100(projectId, ApiConstants.APPROVAL_SUCCESS);
            StaticLog.info("工程量清单的100版本的审批--goArchive100---end");
        } else if (ApiConstants.BUSINESS_APPROVAL_WZ_100.equals(appKind)) {
            StaticLog.info("材料计划转的200版本审批--goVersion200---start");
            // 材料计划转的200版本审批
            plan100Service.goVersion200(ApiConstants.APPROVAL_SUCCESS, projectId);
            StaticLog.info("材料计划转的200版本审批--goVersion200---end");
        } else if (ApiConstants.BUSINESS_APPROVAL_FB_100.equals(appKind)) {
            StaticLog.info("分包计划转的200版本审批--goArchive200---start");
            // 分包计划转的200版本审批
            package100Service.goArchive200(projectId, ApiConstants.APPROVAL_SUCCESS);
            StaticLog.info("分包计划转的200版本审批--goArchive200---end");
        } else if (ApiConstants.BUSINESS_APPROVAL_FB_CONTACTS.equals(appKind)) {
            // 分包合同下达审批

        } else if (ApiConstants.BUSINESS_APPROVAL_REPORT_OUT.equals(appKind)) {
            // TODO: 对外验工月报审批

        } else if (ApiConstants.ENGINEER_APPROVAL_WZ_100_UPD.equals(appKind)) {
            StaticLog.info("材料计划_100版本_修正变更审批--goMerge100---start");
            // 材料计划_100版本_修正变更审批
            plan100Service.goMerge100(ApiConstants.APPROVAL_SUCCESS, Long.valueOf(projectId));
            StaticLog.info("材料计划_100版本_修正变更审批--goMerge100---end");
        } else if (ApiConstants.ENGINEER_APPROVAL_WZ_100_ADD.equals(appKind)) {
            StaticLog.info("材料计划_100版本_追加变更审批--goMerge100---start");
            // 材料计划_100版本_追加变更审批
            plan100Service.goMerge100(ApiConstants.APPROVAL_SUCCESS, Long.valueOf(projectId));
            StaticLog.info("材料计划_100版本_追加变更审批--goMerge100---end");
        } else if (ApiConstants.ENGINEER_APPROVAL_WZ_200_UPD.equals(appKind)) {
            StaticLog.info("材料计划_200版本_修正变更审批--gomergeplan200---start");
            // 材料计划_200版本_修正变更审批
            plan200Service.gomergeplan200(ApiConstants.APPROVAL_SUCCESS, Long.valueOf(projectId));
            StaticLog.info("材料计划_200版本_修正变更审批--gomergeplan200---end");

        } else if (ApiConstants.ENGINEER_APPROVAL_WZ_200_ADD.equals(appKind)) {
            StaticLog.info("材料计划_200版本_追加变更审批--gomergeplan200---start");
            // 材料计划_200版本_追加变更审批
            plan200Service.gomergeplan200(ApiConstants.APPROVAL_SUCCESS, Long.valueOf(projectId));
            StaticLog.info("材料计划_200版本_追加变更审批--gomergeplan200---end");
        } else if (ApiConstants.ENGINEER_APPROVAL_FB_100_UPD.equals(appKind)) {
            StaticLog.info("分包计划_100版本_修正变更审批--goMerge100---start");
            // 分包计划_100版本_修正变更审批
            Map map = (Map) reqData;
            String majorCode = TypeUtils.castToString(map.get("majorCode"));
            String packageNo = TypeUtils.castToString(map.get("majorCode"));
            package100Service.goMerge100(projectId, majorCode, packageNo, String.valueOf(map.get(ApiConstants.REDIS_KEY_USERNAME)));
            StaticLog.info("分包计划_100版本_修正变更审批--goMerge100---end");
        } else if (ApiConstants.ENGINEER_APPROVAL_FB_100_ADD.equals(appKind)) {
            StaticLog.info("分包计划_100版本_追加变更审批--goMerge100---start");
            // 分包计划_100版本_追加变更审批
            Map map = (Map) reqData;
            String majorCode = TypeUtils.castToString(map.get("majorCode"));
            String packageNo = TypeUtils.castToString(map.get("majorCode"));
            package100Service.goMerge100(projectId, majorCode, packageNo, String.valueOf(map.get(ApiConstants.REDIS_KEY_USERNAME)));
            StaticLog.info("分包计划_100版本_追加变更审批--goMerge100---end");
        } else if (ApiConstants.ENGINEER_APPROVAL_FB_200_UPD.equals(appKind)) {
            StaticLog.info("分包计划_200版本_追加变更审批--goMerge200---start");
            // 分包计划_200版本_追加变更审批
            Map map = (Map) reqData;
            String majorCode = TypeUtils.castToString(map.get("majorCode"));
            String packageNo = TypeUtils.castToString(map.get("majorCode"));
            package200Service.goMerge200(projectId, majorCode, packageNo, String.valueOf(map.get(ApiConstants.REDIS_KEY_USERNAME)));
            StaticLog.info("分包计划_200版本_追加变更审批--goMerge200---end");
        } else if (ApiConstants.ENGINEER_APPROVAL_FB_200_ADD.equals(appKind)) {
            StaticLog.info("分包计划_200版本_追加变更审批--goMerge200---start");
            // 分包计划_200版本_追加变更审批
            Map map = (Map) reqData;
            String majorCode = TypeUtils.castToString(map.get("majorCode"));
            String packageNo = TypeUtils.castToString(map.get("majorCode"));
            package200Service.goMerge200(projectId, majorCode, packageNo, String.valueOf(map.get(ApiConstants.REDIS_KEY_USERNAME)));
            StaticLog.info("分包计划_200版本_追加变更审批--goMerge200---end");
        } else if (ApiConstants.ENGINEER_APPROVAL_WZ_REQ.equals(appKind)) {
            StaticLog.info("材料计划申请_审批--goPurseSuccess---start");
            Map applyMap = (Map) reqData;
            List<BusMaterialPlan100> pnlist = (List<BusMaterialPlan100>) applyMap.get("plan100detail");
            BusPurchase purchase = (BusPurchase) applyMap.get("purchase");
            // 材料计划申请_审批
            plan100Service.goPurseSuccess(ApiConstants.APPROVAL_SUCCESS, projectId, pnlist, purchase, userNum);
            StaticLog.info("材料计划申请_审批--goPurseSuccess---end");

        } else if (ApiConstants.ENGINEER_APPROVAL_FB_REQ.equals(appKind)) {
            StaticLog.info("对内验工月报_审批--saveBusReportAfter---start");
            Map<String, Object> approvalMap = (Map<String, Object>) reqData;
            List<BusReport> busReportsOut = (List<BusReport>) approvalMap.get(ApiConstants.REDIS_KEY_BUSREPORT_APPROVALS);
            Integer ver = Integer.valueOf(String.valueOf(approvalMap.get(ApiConstants.REDIS_KEY_BUSREPORT_VER)));
            syncSrmService.busReportServiceImpl(busReportsOut, ver);
            // 对内验工月报_审批
//            BusReport report = (BusReport)reqData;
//            EntityMap mapIn = new EntityMap();
//            // 需要参数materialId,reportMonth,projectId,majorCode,packageNo,
//            mapIn.put("materialId", report.getMaterialId());
//            mapIn.put("reportMonth", report.getReportMonth());
//            mapIn.put("projectId", report.getProjectId());
//            mapIn.put("majorCode", report.getMajorCode());
//            mapIn.put("packageNo", report.getPackageNo());
//            busReportService.saveBusReportAfter(mapIn, 1);
            StaticLog.info("对内验工月报_审批--saveBusReportAfter---end");
        }
        StaticLog.info("------todoMake-----end");
    }

    public void setRedisForOaApproval(Object reqData, String requestId, String appKind, Long projectId, BusOaApprovalSync busOaApprovalSync) throws Exception {
        if (ApiConstants.ENGINEER_APPROVAL_WZ_100_UPD.equals(appKind)
            || ApiConstants.ENGINEER_APPROVAL_WZ_100_ADD.equals(appKind)
            || ApiConstants.ENGINEER_APPROVAL_WZ_200_UPD.equals(appKind)
            || ApiConstants.ENGINEER_APPROVAL_WZ_200_ADD.equals(appKind)
            || ApiConstants.ENGINEER_APPROVAL_FB_100_UPD.equals(appKind)
            || ApiConstants.ENGINEER_APPROVAL_FB_100_ADD.equals(appKind)
            || ApiConstants.ENGINEER_APPROVAL_FB_200_UPD.equals(appKind)
            || ApiConstants.ENGINEER_APPROVAL_FB_200_ADD.equals(appKind)
            || ApiConstants.ENGINEER_APPROVAL_WZ_REQ.equals(appKind)) {
            Map map = (Map) reqData;
            if (!ApiConstants.ENGINEER_APPROVAL_WZ_REQ.equals(appKind)) {
                Collection<Object> reqS = pmsOaUtil.getPlanPackData(appKind, projectId);
                StaticLog.info("计划数据更新到redis中");
                map.put(ApiConstants.REDIS_KEY_PLAN_DATA_COLLECTION, reqS);
            }
            redisUtils.setMap(requestId, map);

            if (ApiConstants.ENGINEER_APPROVAL_FB_100_UPD.equals(appKind)
                || ApiConstants.ENGINEER_APPROVAL_FB_100_ADD.equals(appKind)
                || ApiConstants.ENGINEER_APPROVAL_FB_200_UPD.equals(appKind)
                || ApiConstants.ENGINEER_APPROVAL_FB_200_ADD.equals(appKind)) {
                busOaApprovalSync.setMajorCode(TypeUtils.castToString(map.get("majorCode")));
                busOaApprovalSync.setPackageNo(TypeUtils.castToString(map.get("packageNo")));
            }
            if (ApiConstants.ENGINEER_APPROVAL_WZ_100_UPD.equals(appKind)
                || ApiConstants.ENGINEER_APPROVAL_WZ_100_ADD.equals(appKind)
                || ApiConstants.ENGINEER_APPROVAL_WZ_200_UPD.equals(appKind)
                || ApiConstants.ENGINEER_APPROVAL_WZ_200_ADD.equals(appKind)
                || ApiConstants.ENGINEER_APPROVAL_WZ_REQ.equals(appKind)) {
                String majorCode = "";
                List<String> majorCodes = busMajorService.getUserMajors(OpenHelper.getUserId());
                if (majorCodes.size() > 0) {
                    if (!majorCodes.contains("P99")) {
                        majorCode = majorCodes.get(0);
                    }
                }
                busOaApprovalSync.setMajorCode(majorCode);
            }

        } else {
            if (ApiConstants.ENGINEER_APPROVAL_FB_REQ.equals(appKind)) {
                Map<String, Object> map = (Map) reqData;
                redisUtils.setMap(requestId, map);
            } else {
                redisUtils.set(requestId, reqData);
            }
        }
    }
}
